{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第五次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer5文件夹下，**谢绝交到master下**\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在11月7日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  龚剑\n",
    "+ 学号  0163275"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一、贫困户模型\n",
    "+ 创建一个类，包含贫困户的义务教育保障、住房安全、饮水安全、肉蛋奶豆的四个属性\n",
    "+ 包含一个是否贫困的预测，如果四个属性有两个以上没有保障（>2)则输出为贫困户\n",
    "+ 对贫困户，采取相应措施（输入参数）对其进行帮扶，使其脱贫\n",
    "+ 至少生成三个实例\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "不贫困\n",
      "不实行补贴\n",
      "不实行补贴\n",
      "不实行补贴\n",
      "不实行补贴\n",
      "\n",
      "\n",
      "贫困户\n",
      "国家免费资助九年教育\n",
      "住房达标\n",
      "国家每月提供100升纯净水\n",
      "营养达标\n",
      "\n",
      "\n",
      "贫困户\n",
      "教育达标\n",
      "住房达标\n",
      "国家每月提供100升纯净水\n",
      "营养达标\n"
     ]
    }
   ],
   "source": [
    "class family(object):\n",
    "    def __init__(self,x1,x2,x3,x4):\n",
    "        self.education=x1\n",
    "        self.house=x2\n",
    "        self.water=x3\n",
    "        self.proteins=x4\n",
    "        if x1+x2+x3+x4>2:\n",
    "            print('贫困户')\n",
    "        else:\n",
    "            print('不贫困')\n",
    "    def edu(self,xueli):\n",
    "        if self.education+self.house+self.water+self.proteins<=2:\n",
    "            print(\"不实行补贴\")\n",
    "        elif self.education==1 and xueli<9:\n",
    "            print(\"国家免费资助九年教育\")\n",
    "        else:\n",
    "            print(\"教育达标\")\n",
    "    def hou(self,mianji):\n",
    "        if self.education+self.house+self.water+self.proteins<=2:\n",
    "            print(\"不实行补贴\")\n",
    "        elif self.house==1 and mianji<50:\n",
    "            print(\"国家每月发放500元住房补贴\")\n",
    "        else:\n",
    "            print(\"住房达标\")\n",
    "    def wat(self,shuizhi):\n",
    "        if self.education+self.house+self.water+self.proteins<=2:\n",
    "            print(\"不实行补贴\")\n",
    "        elif self.water==1 and shuizhi<75:\n",
    "            print(\"国家每月提供100升纯净水\")\n",
    "        else:\n",
    "            print(\"饮水达标\")\n",
    "    def pro(self,yingyang):\n",
    "        if self.education+self.house+self.water+self.proteins<=2:\n",
    "            print(\"不实行补贴\")\n",
    "        elif self.proteins==1 and yingyang<60:\n",
    "            print(\"国家每月发放200元营养补贴\")\n",
    "        else:\n",
    "            print(\"营养达标\")\n",
    "\n",
    "\n",
    "\n",
    "family_1=family(1,1,0,0)\n",
    "family_1.edu(xueli=8)\n",
    "family_1.hou(mianji=45)\n",
    "family_1.wat(shuizhi=45)\n",
    "family_1.pro(yingyang=60)\n",
    "print(\"\\n\")\n",
    "family_2=family(1,0,1,1)\n",
    "family_2.edu(xueli=6)\n",
    "family_2.hou(mianji=45)\n",
    "family_2.wat(shuizhi=25)\n",
    "family_2.pro(yingyang=70)\n",
    "print(\"\\n\")\n",
    "family_3=family(1,1,1,0)\n",
    "family_3.edu(xueli=10)\n",
    "family_3.hou(mianji=85)\n",
    "family_3.wat(shuizhi=45)\n",
    "family_3.pro(yingyang=60)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二: 学生信息\n",
    "+ 创建一个类，包含姓名、分数、睡眠时间三个属性\n",
    "+ 包含一个胖瘦的预测，如果分数>90，且睡眠时间少于6小时，输出“BMI可能偏大”，否则输出“体重正常”\n",
    "+ 为使得标准（90分、6小时）可以调整，标准应设为输入的参数\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BMI可能偏大\n",
      "体重正常\n",
      "BMI可能偏大\n"
     ]
    }
   ],
   "source": [
    "class Student(object):\n",
    " \n",
    "  def __init__(self, name, score, sleep):\n",
    "    self.name = name\n",
    "    self.score = score\n",
    "    self.sleep=sleep\n",
    "  \n",
    "  def get_grade(self,c1,c2):\n",
    "    if self.score >= c1 and self.sleep<c2:\n",
    "        print(\"BMI可能偏大\")\n",
    "    else:\n",
    "        print(\"体重正常\")\n",
    "\n",
    "stu_1=Student('Bob',88,5)\n",
    "stu_1.get_grade(85,6)\n",
    "\n",
    "stu_2=Student('Ace',70,8)\n",
    "stu_2.get_grade(80,7)\n",
    "\n",
    "stu_3=Student('Dive',95,7)\n",
    "stu_3.get_grade(90,7.5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三：“跑步社”成员类\n",
    "+ 创建一个“跑步社”成员类，以学生信息类为父类\n",
    "+ 添加一个属性为跑步\n",
    "+ 如果跑步时间大于30分钟，如果之前预测为“BMI可能偏大”，则输出为“趋向正常”\n",
    "+ 至少生成三个实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "趋向正常\n",
      "体重正常\n",
      "BMI可能偏大\n"
     ]
    }
   ],
   "source": [
    "class run(Student):\n",
    "    def __init__(self,name,score,sleep,running):\n",
    "        super().__init__(name,score,sleep)\n",
    "        self.running=running\n",
    "\n",
    "    def get_run(self,c1,c2):\n",
    "        if self.score >= c1 and self.sleep<c2 and self.running<=30:\n",
    "            print(\"BMI可能偏大\")\n",
    "        elif self.score >= c1 and self.sleep<c2 and self.running>30:\n",
    "            print(\"趋向正常\")\n",
    "        else:\n",
    "            print(\"体重正常\")\n",
    "stu_1=run('Bob',88,5,40)\n",
    "stu_1.get_run(85,6)\n",
    "\n",
    "stu_2=run('Ace',70,8,30)\n",
    "stu_2.get_run(80,7)\n",
    "\n",
    "stu_3=run('Dive',95,7,27)\n",
    "stu_3.get_run(90,7.5)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
